Log plan metadata changes in unified history feed (COPLAN-26)#115
Log plan metadata changes in unified history feed (COPLAN-26)#115HamptonMakes wants to merge 1 commit into
Conversation
Adds a CoPlan::PlanEvent model alongside PlanVersion so that metadata mutations (status, title, tags, references, plan_type) are visible in the History tab with actor, timestamp, and before/after values — without bumping the content revision counter. - New coplan_plan_events table + model + admin - Plans::LogEvent service normalizes & no-ops unchanged events - Plan#history_items merges versions + events into one feed - _event_item partial renders inline metadata entries; content versions remain clickable into the diff frame - Web title/status, references, and API PATCH paths now log events - History badge count includes both versions and events - Turbo broadcasts prepend new events live and refresh the count badge Refs COPLAN-26 Amp-Thread-ID: https://ampcode.com/threads/T-019e22e9-1c86-71bc-a076-f5e6d06b03d0 Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2506d9653
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| if permitted.key?(:title) && @plan.saved_change_to_title? | ||
| Plans::LogEvent.call( | ||
| plan: @plan, actor: current_user, event_type: "title_changed", |
There was a problem hiding this comment.
Preserve API actor type when logging metadata
When this API endpoint is called with a bearer token, current_user is the token owner, while the rest of the API records content edits with api_author_type == "local_agent" and api_actor_id from the token. Passing current_user here makes all API title/status/tag/reference metadata events look like human edits by the owner, so the new history feed gives the wrong answer for agent-driven metadata changes; the other Plans::LogEvent.call sites in this action have the same attribution issue.
Useful? React with 👍 / 👎.
Why
The History tab only shows content revisions today. Metadata mutations — title, status, tags, references, plan_type — are silent. There's no answer to "who changed the status to developing yesterday?" or "when did this tag disappear?" without digging through audit logs.
COPLAN-26 asks for these changes to show up in the History tab with actor, timestamp, and before/after, without bumping
current_revision(which would conflate content edits with metadata churn).What
A new
CoPlan::PlanEventmodel that lives alongsidePlanVersion. Content snapshots and metadata entries are two different things conceptually —PlanVersionrequirescontent_markdown/content_sha256and drives revision numbering, while metadata events are append-only log entries with before/after values. Forcing them into one table would make both messier.coplan_plan_eventswith actor, actor_type, event_type, field, before_value, after_value, metadata JSON, created_at. Standard CoPlan conventions (UUID PK, no DB-level JSON default, frozen constants +inclusion:validation).Plans::LogEventservice: normalizes values to strings, no-ops when before == after, infers actor_type.Plan#history_itemsmergesplan_versions+plan_eventssorted newest-first.history_kind(:version/:event) lets templates branch without class introspection.PlansController#update(title),PlansController#update_status,ReferencesController#create/destroyApi::V1::PlansController#updatelogs title, status, and tag add/remove diffs in a single request; reference additions emitreference_addedApplicationControllerso broadcasted partials can callrender_event_summary.Event types defined:
status_changed,title_changed,plan_type_changed,tag_added,tag_removed,reference_added,reference_removed.plan_type_changedis model-ready; the mutation path lands with COPLAN-25.Verification
bundle exec rspec— 857 examples, 0 failures. New coverage:spec/services/plans/log_event_spec.rb— service normalization + no-op behaviorspec/models/plan_event_spec.rb— validations, defaults, cascade configurationspec/requests/plan_events_spec.rb— every mutation surface (web title/status/references, API title/status/tags/references) actually emits the right events, andPlan#history_itemsinterleaves correctly.References
@codex please review
🤖 Generated with Amp